package com.firstgroup.controller;

import com.firstgroup.Utils.ResponseResult;
import com.firstgroup.domain.Comment;
import com.firstgroup.domain.Interviewers;
import com.firstgroup.domain.User;
import com.firstgroup.repository.InterviewersRepository;
import com.firstgroup.repository.UserRepository;
import com.firstgroup.service.Impl.CommentServiceImpl;
import com.firstgroup.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional;

@Api(tags = "面试官评价(评论)类")
@RestController
public class CommentController {

    @Autowired
    CommentServiceImpl commentServiceImpl;
    @Autowired
    UserRepository userRepository;
    @Autowired
    InterviewersRepository interviewersRepository;
    @Resource
    UserService userService;

    /**
     * 遍历一面评价
     * @param interviewerId
     * @return
     */
    @RequestMapping(value = "/findByInterviewerAndState",method = RequestMethod.GET)
    @ApiOperation(value = "遍历一面的评论")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "面试者id",name = "interviewerId",required = true,type = "int")
    })
    public List<Comment> findByInterviewerAndState(int interviewerId){
    List<Comment>list= commentServiceImpl.findByInterviewrIdAndState(interviewerId,"一面的评价");
        return list;
    }

    /**
     * 遍历二面评论
     * @param interviewerId
     * @return
     */
    @RequestMapping(value = "findByInterviewerIdAndStateTwo",method = RequestMethod.GET)
    @ApiOperation(value = "遍历二面的评论")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "面试者id",name = "interviewerId",required = true,type = "int")
    })
    public List<Comment> findByInterviewerIdAndStateTwo(int interviewerId){
        List<Comment> list=commentServiceImpl.findByInterviewerIdAndStateTwo(interviewerId,"二面的评价");
        return list;
    }

    /**
     * 在三面遍历该新生所有评价
     * @param interviewerId
     * @return
     */
    @RequestMapping(value = "findComments",method = RequestMethod.GET)
    @ApiOperation(value = "在三面遍历所有评价")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "面试者id",name = "interviewerId",required = true,type = "int")
    })
    public List<Comment> findComments(int interviewerId){
            List<Comment> list=commentServiceImpl.findCountss(interviewerId);
        return list;
    }




    @RequestMapping(value = "addCommentOne",method = RequestMethod.POST)
    @ApiOperation(value = "在一面添加评价")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "面试官id（userid）",name = "userid",required = true,type = "int"),
            @ApiImplicitParam(value = "面试者id（interviewerId）",name = "interviewerId",required = true,type = "int"),
            @ApiImplicitParam(value = "评论内容",name = "content",required = true,type = "String")
    })
    public Comment addCommnetOne(int userid,int interviewerId,String content){
      Comment comment=new Comment();
      User user= userRepository.findById(userid);
      comment.setUserid(userid);
      comment.setUsername(user.getName());
      Interviewers interviewers= interviewersRepository.findByInterviewersId(interviewerId);
      comment.setInterviewrId(interviewerId);
      comment.setInterviewrName(interviewers.getName());
      comment.setState("一面的评价");
      comment.setContent(content);
   Comment comment1=   commentServiceImpl.addComments(comment);
      return comment1;
    }


    @RequestMapping(value = "addCommentTwo",method = RequestMethod.POST)
    @ApiOperation(value = "在二面添加评价")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "面试官id（userid）",name = "userid",required = true,type = "int"),
            @ApiImplicitParam(value = "面试者id（interviewerId）",name = "interviewerId",required = true,type = "int"),
            @ApiImplicitParam(value = "评论内容",name = "content",required = true,type = "String")
    })

    public Comment addCommnetTwo(int userid,int interviewerId,String content){
        Comment comment=new Comment();
        User user= userRepository.findById(userid);
        comment.setUserid(userid);
        comment.setUsername(user.getName());
        Interviewers interviewers= interviewersRepository.findByInterviewersId(interviewerId);
        comment.setInterviewrId(interviewerId);
        comment.setInterviewrName(interviewers.getName());
        comment.setState("二面的评价");
        comment.setContent(content);
        Comment comment1=   commentServiceImpl.addComments(comment);
        return comment1;
    }
}
